{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"UTF-8\""
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### pry-docの読み込み\n",
    "#require \"/root/jupyter/vendor/bundle/ruby/2.3.0/gems/pry-doc-0.10.0/lib/pry-doc\"\n",
    "#require \"/root/git_jupyter_notebook/Ruby/vendor/bundle/ruby/2.3.0/gems/pry-doc-0.10.0/lib/pry-doc\"\n",
    "require \"/Users/ftakao2007/jupyter/vendor/bundle/ruby/2.3.0/gems/pry-doc-0.10.0/lib/pry-doc\"\n",
    "### エンコーディングをUTF-8に設定\n",
    "Encoding.default_external = \"UTF-8\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1を0では割れません\n"
     ]
    }
   ],
   "source": [
    "begin\n",
    "  1/ 0\n",
    "rescue\n",
    "  puts \"1を0では割れません\"\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\u001b[1mFrom:\u001b[0m array.c (C Method):\n",
      "\u001b[1mOwner:\u001b[0m Array\n",
      "\u001b[1mVisibility:\u001b[0m public\n",
      "\u001b[1mSignature:\u001b[0m zip(*arg1)\n",
      "\u001b[1mNumber of lines:\u001b[0m 17\n",
      "\n",
      "Converts any arguments to arrays, then merges elements of \u001b[32mself\u001b[0m with\n",
      "corresponding elements from each argument.\n",
      "\n",
      "This generates a sequence of ary.size _n_-element arrays,\n",
      "where _n_ is one more than the count of arguments.\n",
      "\n",
      "If the size of any argument is less than the size of the initial array,\n",
      "\u001b[32mnil\u001b[0m values are supplied.\n",
      "\n",
      "If a block is given, it is invoked for each output \u001b[32marray\u001b[0m, otherwise an\n",
      "array of arrays is returned.\n",
      "\n",
      "   a = [ \u001b[1;34m4\u001b[0m, \u001b[1;34m5\u001b[0m, \u001b[1;34m6\u001b[0m ]\n",
      "   b = [ \u001b[1;34m7\u001b[0m, \u001b[1;34m8\u001b[0m, \u001b[1;34m9\u001b[0m ]\n",
      "   [\u001b[1;34m1\u001b[0m, \u001b[1;34m2\u001b[0m, \u001b[1;34m3\u001b[0m].zip(a, b)   \u001b[1;34m#=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]\u001b[0m\n",
      "   [\u001b[1;34m1\u001b[0m, \u001b[1;34m2\u001b[0m].zip(a, b)      \u001b[1;34m#=> [[1, 4, 7], [2, 5, 8]]\u001b[0m\n",
      "   a.zip([\u001b[1;34m1\u001b[0m, \u001b[1;34m2\u001b[0m], [\u001b[1;34m8\u001b[0m])    \u001b[1;34m#=> [[4, 1, 8], [5, 2, nil], [6, nil, nil]]\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "show-doc Array#zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "(pry):61: warning: already initialized constant HOGE\n",
      "(pry):53: warning: previous definition of HOGE was here\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "69875354850480\n",
      "69875354850480\n"
     ]
    }
   ],
   "source": [
    "HOGE = \"haga\"\n",
    "puts HOGE.object_id\n",
    "HOGE << \"Fuga\"\n",
    "puts HOGE.object_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SyntaxError: (eval):3: dynamic constant assignment\n",
      "  ABC = 1\n",
      "       ^\n"
     ]
    }
   ],
   "source": [
    "def method1\n",
    "  ABC = 1\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "(pry):70: warning: already initialized constant FUGAA\n",
      "(pry):68: warning: previous definition of FUGAA was here\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "FUGAA=2\n",
    "FUGAA.freeze\n",
    "FUGAA=3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\u001b[1mFrom:\u001b[0m variable.c (C Method):\n",
      "\u001b[1mOwner:\u001b[0m Module\n",
      "\u001b[1mVisibility:\u001b[0m public\n",
      "\u001b[1mSignature:\u001b[0m const_missing(arg1)\n",
      "\u001b[1mNumber of lines:\u001b[0m 29\n",
      "\n",
      "Invoked when a reference is made to an undefined constant in\n",
      "\u001b[1mmod\u001b[0m. It is passed a symbol for the undefined constant, and\n",
      "returns a value to be used for that constant. The\n",
      "following code is an example of the same:\n",
      "\n",
      "  \u001b[32mdef\u001b[0m \u001b[1;34;4mFoo\u001b[0m.\u001b[1;34mconst_missing\u001b[0m(name)\n",
      "    name \u001b[1;34m# return the constant name as Symbol\u001b[0m\n",
      "  \u001b[32mend\u001b[0m\n",
      "\n",
      "  \u001b[1;34;4mFoo\u001b[0m::\u001b[1;34;4mUNDEFINED_CONST\u001b[0m    \u001b[1;34m#=> :UNDEFINED_CONST: symbol returned\u001b[0m\n",
      "\n",
      "In the next example when a reference is made to an undefined constant,\n",
      "it attempts to load a file whose name is the lowercase version of the\n",
      "constant (thus class \u001b[1;34;4mFred\u001b[0m is assumed to be in file\n",
      "fred.rb).  If found, it returns the loaded class. It\n",
      "therefore implements an autoload feature similar to Kernel#autoload and\n",
      "Module#autoload.\n",
      "\n",
      "  \u001b[32mdef\u001b[0m \u001b[1;34;4mObject\u001b[0m.\u001b[1;34mconst_missing\u001b[0m(name)\n",
      "    @looked_for ||= {}\n",
      "    str_name = name.to_s\n",
      "    raise \u001b[31m\u001b[1;31m\"\u001b[0m\u001b[31mClass not found: #{name}\u001b[0m\u001b[31m\u001b[1;31m\"\u001b[0m\u001b[31m\u001b[0m \u001b[32mif\u001b[0m @looked_for[str_name]\n",
      "    @looked_for[str_name] = \u001b[1;34m1\u001b[0m\n",
      "    file = str_name.downcase\n",
      "    require file\n",
      "    klass = const_get(name)\n",
      "    \u001b[32mreturn\u001b[0m klass \u001b[32mif\u001b[0m klass\n",
      "    raise \u001b[31m\u001b[1;31m\"\u001b[0m\u001b[31mClass not found: #{name}\u001b[0m\u001b[31m\u001b[1;31m\"\u001b[0m\u001b[31m\u001b[0m\n",
      "  \u001b[32mend\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "show-doc Module#const_missing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "true\n",
      "false\n"
     ]
    }
   ],
   "source": [
    "puts /[ab]c/ != \"ac\"\n",
    "puts /[ab]c/ !~ \"ac\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.\n",
      "1\n",
      "2\n",
      "Fizz\n",
      "4\n",
      "Buzz\n",
      "Fizz\n",
      "7\n",
      "8\n",
      "Fizz\n",
      "Buzz\n",
      "11\n",
      "Fizz\n",
      "13\n",
      "14\n",
      "Fizz Buzz\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "def fizz_buzz(num)\n",
    "  return \"0.\" if num == 0\n",
    "  return \"Fizz\" if num % 15 != 0 && num % 3 == 0\n",
    "  return \"Buzz\" if num % 3 != 0 && num % 15 != 0 && num % 5 == 0\n",
    "  return \"Fizz Buzz\" if num % 15 == 0\n",
    "  return num\n",
    "end\n",
    "\n",
    "0.upto(15) do |i|\n",
    "  puts fizz_buzz(i)\n",
    "end\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "orの使い所\n",
      "hoge\n"
     ]
    }
   ],
   "source": [
    "puts \"orの使い所\"\n",
    "a = nil\n",
    "a or puts \"hoge\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Ruby 2.3.1",
   "language": "ruby",
   "name": "ruby"
  },
  "language_info": {
   "file_extension": ".rb",
   "mimetype": "application/x-ruby",
   "name": "ruby",
   "version": "2.3.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
